package net.xiangcaowuyu.resttemplate.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import net.xiangcaowuyu.resttemplate.entity.AmapGeoParameters;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author laughing
 * @date 2020/10/2
 * @site https://www.xiangcaowuyu.net
 */
@RestController
public class AmapController {

    private final String url = "https://restapi.amap.com/v3/geocode/geo";
    private final String key = "c17ba5b2f9277ed0326ab4fa6019b0cf";

    @Resource
    RestTemplate restTemplate;

    /**
     * 地理位置编码
     *
     * @return
     * @throws JsonProcessingException
     */
    @RequestMapping("geo")
    public String geo() throws JsonProcessingException {
        String url = this.url + "?key=" + this.key + "&address=" + "山东省济南市历下区龙奥大厦" + "&output=JSON";
        ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.GET, null, String.class);
        return responseEntity.getBody();
    }

}
